import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [

    {
        path: '/home',
        name: 'Home',
        component: () => import('../views/Home.vue'),
    },
    {
        path: '/login',
        name: 'About',
        component: () => import('../views/Login.vue'),
    },

    {
        path: '/sign',
        name: 'Sign',
        component: () => import('../views/Sign.vue')
    },
    {
        path: '/',
        name: 'About',

        component: () => import('../views/About.vue'),
    },
    {
        path: '/videoabout',
        name: 'About2',

        component: () => import('../views/video_About.vue'),
        children: [
            {
                path: '/videoabout/videotable',
                name: 'Table',
                component: () => import('../views/video_Table.vue')
            },
            {
                path: '/videoabout/usertable',
                name: 'Table2',
                component: () => import('../views/user_Table.vue')
            }
        ]
    },
    {
        path: '/video',
        name: 'Video',

        component: () => import('../views/Video.vue')
    },
    {
        path: '/submission',
        name: 'Submission',
        component: () =>
            import( /* webpackChunkName: "videoSubmission" */ '../views/Submission.vue'),
        children: [
            {
                path: '/submission/videoSubmission',
                name: 'VideoSubmission',
                component: () =>
                    import( /* webpackChunkName: "videoSubmission" */ '../views/VideoSubmission.vue')
            },
            {
                path: '/submission/activeSubmission',
                name: 'ActiveSubmission',
                component: () =>
                    import( /* webpackChunkName: "activeSubmission" */ '../views/ActiveSubmission.vue')
            },
            {
                path: '/submission/pasterSubmission',
                name: 'PasterSubmission',
                component: () =>
                    import( /* webpackChunkName: "/pasterSubmission" */ '../views/PasterSubmission.vue')
            },
            {
                path: '/submission/videoMaterial',
                name: 'VideoMaterial',
                component: () =>
                    import( /* webpackChunkName: "/videoMaterial" */ '../views/VideoMaterial.vue')
            },
        ]
    },
    {
        path: '/*',
        name: '404',
        component: () => import('../views/404.vue')
    }
]

const router = new VueRouter({
    routes
})
router.beforeEach((to, from, next) => {
    if (to.path == '/' || to.path == '/video') {
        next()
    } else if (to.path == '/home' || to.path == '/submission/videoSubmission') {
        const tokenStr = window.sessionStorage.getItem('token')
        if (!tokenStr) {
            next('/login')
        } else {
            next()
        }
    } else if (to.path == '/videoabout') {
        console.log(1234);
        const tokenStr = window.sessionStorage.getItem('token')
        if (tokenStr != "123123") {
            next('/login')
        }else{
            next()
        }
    } else {
        next()
    }
})

export default router
